<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.html.parameter' );
$params = JFactory::getApplication()->getTemplate(true)->params;
$uid = (isset($_SERVER['uid']) ? $_SERVER['uid'] : 0 );
$uid = (isset($_GET['uid']) ? $_GET['uid'] : $uid );
$colorchoose = (isset($_GET['colorchoose']) ? $_GET['colorchoose'] : '' );
global $color;
if(isset($_POST['resetColor']) && $_POST['resetColor'] == 1 ){
	$file = JPATH_THEMES."/".$this->template."/params/".'params_'.$uid.'.ini';
	unlink($file);
}else if(isset($_POST['saveColor'])){
	$content = "color=".$_POST['color']."\n";
	$content .= "bgbody=".$_POST['bgBodyInput']."\n";
	$content .= "bgblock=".$_POST['bgblockColorInput']."\n";
	$content .= "bgwall=".$_POST['bgWallColorInput']."\n";
	$content .= "textwall=".$_POST['textWallColorInput']."\n";
	$content .= "textwalllink=".$_POST['textWallLinkColorInput']."\n";
	$content .= "linecolor=".$_POST['lineColorInput']."\n";
	$content .= "tabcolor=".$_POST['tabColorInput']."\n";
	$content .= "menucolor=".$_POST['menuTextColorInput']."\n";
	$content .= "address=".$_POST['addressColorInput']."\n";
	$content .= "phone=".$_POST['phoneColorInput']."\n";
	$content .= "hour=".$_POST['hourColorInput']."\n";
	$content .= "hourtext=".$_POST['hourTextColorInput']."\n";
	$content .= "followcolor=".$_POST['followcolorInput']."\n";

	jimport('joomla.filesystem.file');
	$file = JPATH_THEMES."/".$this->template."/params/".'params_'.$uid.'.ini';
	JFile::write($file, $content);
}
$loadcolor = false;
if($uid){
	$user_id = $uid;
	if (is_readable( JPATH_THEMES."/".$this->template."/params/".'params_'.$user_id.'.ini' ) )
	{
		$content = file_get_contents(JPATH_THEMES."/".$this->template."/params/".'params_'.$user_id.'.ini');
		$loadcolor = true;
	}else{
		$content = file_get_contents(JPATH_THEMES."/".$this->template."/params/".'params.ini');
	}
	$arr_color = explode("\n", $content);
	$params = array();
	foreach($arr_color as $value){
		@$item = explode("=", $value);
		@$params[$item[0]] = trim($item[1]);
	}
	$this->params = $params;
}

$app = JFactory::getApplication();
$doc = JFactory::getDocument();
// Add JavaScript Frameworks
JHtml::_('bootstrap.framework');

// Add Stylesheets
$doc->addStyleSheet('templates/'.$this->template.'/css/css3.css');
$doc->addStyleSheet('templates/'.$this->template.'/css/stylesheet.css');
$doc->addStyleSheet('templates/'.$this->template.'/css/style.css');
$doc->addScript('templates/'.$this->template.'/js/jquery-ui.js');
$doc->addStyleSheet('css/mooRainbow.css');

// Load optional RTL Bootstrap CSS
JHtml::_('bootstrap.loadCss', false, $this->direction);

// Add current user information
$user = JFactory::getUser();

?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" dir="<?php echo $this->direction; ?>">
<head>
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
	<jdoc:include type="head" />
	<?php if($colorchoose){?>
		<script>
		var jsbgblock 		= '<?php echo $this->params['bgblock'];?>';
		var jsbgwall 		= '<?php echo $this->params['bgwall'];?>';
		var jstextwall 		= '<?php echo $this->params['textwall'];?>';
		var jstextwalllink 	= '<?php echo $this->params['textwalllink'];?>';
		var jsline			= '<?php echo $this->params['linecolor'];?>';
		var jstab 			= '<?php echo $this->params['tabcolor'];?>';
		var jsmenutext 		= '<?php echo $this->params['menucolor'];?>';
		var jsaddress 		= '<?php echo $this->params['address'];?>';
		var jsphone 		= '<?php echo $this->params['phone'];?>';
		var jshour 			= '<?php echo $this->params['hour'];?>';
		var jshourtext 		= '<?php echo $this->params['hourtext'];?>';
		</script>
		<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />

		<script type="text/javascript">
		jQuery(function() {
			jQuery( "#dialog2" ).dialog({
				autoOpen: false,
				show: {
					effect: "blind",
					duration: 1000
				},
				hide: {
					effect: "explode",
					duration: 1000
				}
			});
			jQuery( "#opener" ).click(function() {
				jQuery( "#dialog2" ).dialog( "open" );
			});
		});
        function openBgr(){
        	jQuery( "#dialog2" ).dialog( "open" );
        }
        </script>
		<link rel="stylesheet" href="css/mooRainbow.css" type="text/css">
		<link rel="stylesheet" href="http://jqueryui.com/jquery-wp-content/themes/jqueryui.com/style.css" />
		<script type="text/javascript" src="js/mootools.js"></script>
		<script type="text/javascript" src="js/mooRainbow.js"></script>
		<script type="text/javascript" src="<?php echo $this->baseurl ?>/templates/<?php echo $this->template;?>/js/libs.js"></script>
	<?php }?>
	<?php if($loadcolor){?>
	<style type="text/css">
		<?php if($this->params['bgbody']){?>
		body {background-image:url(<?php echo $this->baseurl ?>/images/background/<?php echo $this->params['bgbody'];?>);}
		<?php }?>
		.left-column{background-color:<?php echo $this->params['bgblock']?>;}
		.main-content{background-color:<?php echo $this->params['bgwall']?>; color:<?php echo $this->params['textwall']?>;}
		.main-content a{color:<?php echo $this->params['textwalllink']?>;}
		
		.menu a{color:<?php echo $this->params['menucolor']?>;}
		.address-block .address{color:<?php echo $this->params['address']?>;}
		.phone{color:<?php echo $this->params['phone']?>;}
		#hour_operation .title{color:<?php echo $this->params['hour']?>;}
		#hour_operation .hour_detail{color:<?php echo $this->params['hourtext']?>;}
	</style>
	<?php }?>
</head>
<body>
  
<?php if($colorchoose){?>
	<div class="choosecolor">
		<div classs="color-block">
		<p><a onclick="showPopupLayer('chooseColorPopup');" href="javascript:;" class="colorchooserIcon">
			<span>Color Chooser</span>
			</a><a href="javascript:void(0);" onclick="javascript:document.chooseColor.submit();" title="Save">Save</a></p>
		</div>
	</div>
<?php }?>
<div id="all">
   	<div class="left-column"> 
        	<div class="logo">
	        	<a href="index.php">
     				<h1>Nail <span>&</span> Spa</h1>
				</a>
				<p>SKIN CARE SYSTEM FACE & BODY POLISHER</p>
            </div>    
            <jdoc:include type="modules" name="client_phone" style="none" />     
            <div class="main-menu">
            	 <div id="jv-mainnav">
                    <div class="jv-block">
                      <div class="jv-inner clearfix">
                        <div id="menu">
                            <jdoc:include type="modules" name="client_menu" style="" />
                        </div>	        
                      </div>
                     
                    </div>
                  </div>
            </div>
            <jdoc:include type="modules" name="client_hour" style="none" />
            <p class="copyright">©2013 <a href="#">COED Consulting Group</a>, Inc.</p>
            <jdoc:include type="modules" name="client_social" style="jv" />
        </div>
        
        <div class="main-content" id="main-content">
        	 <div class="jv-inner">
                  <div id="jv-content">
                                    <?php 
                                    $id = JRequest::getVar('id',0);
                                    $Itemid = JRequest::getVar('Itemid',0);
                                    $catid = JRequest::getVar('catid',0);
                                    $view = JRequest::getVar('view','');
                                    if( ($view=='featured' ) ) { ?>
                                    	<div class="article">
                                        	<jdoc:include type="modules" name="client_welcome" style="none" />
                                        </div>
                                    <?php }elseif(in_array($Itemid,array(2,5,22,21) ) ){?>
                                            <div class="left-block">
                                                <?php if($this->countModules('user_submenu')) { ?>
                                                    <jdoc:include type="modules" name="user_submenu" />
                                                <?php }?>
                                            </div>
                                            <div class="right-block">
                                                <div class="content">
                                                     <jdoc:include type="component" />
                                                </div>
                                            </div>
                                    <?php }else{?>
                                         <div class="article"><jdoc:include type="component" /></div>
                                    <?php }?>
                                
               	  </div>
            </div>   
        </div>
        
        <div class="bottom-menu">
        	<jdoc:include type="modules" name="client_footer_menu" style="" />
        </div>
        
</div>
				
	<?php if($colorchoose){?>
	<div id="dialog2" title="Background Image">
	<?php 
	$dir = 'images/background';
	$arr_rotate = array_diff(scandir($dir), array('..', '.'));
	$extensions = array('jpg','png','gif','jpeg');
	
	foreach($arr_rotate as $key=>$value){
		$extension = strtolower( pathinfo( $value, PATHINFO_EXTENSION ) );
		if ( in_array( $extension , $extensions )){
			echo '<a href="javascript:void(0)" onclick="setBg(\''.$value.'\');"><img '.(($this->params['bgbody'] == $value) ? 'class="selected"' : '').' src="'.$dir."/".$value.'" width="120"/></a>';
		}
	}
	if(is_dir($dir."/".$uid)){
		$arr_rotate = array_diff(scandir($dir."/".$uid), array('..', '.'));
		foreach($arr_rotate as $key=>$value){
			$extension = strtolower( pathinfo( $value, PATHINFO_EXTENSION ) );
			if ( in_array( $extension , $extensions )){
				echo '<a href="javascript:void(0)" onclick="setBg(\''.$uid."/".$value.'\');"><img '.(($this->params['bgbody'] == $uid."/".$value) ? 'class="selected"' : '').' src="'.$dir."/".$uid."/".$value.'"  width="120"/></a>';
			}
		}
	}
	?>
	</div>
		<div id="chooseColorPopup" class="popup">
			<div class="popupTitle">
				<h3>Color Choose</h3>
				<a id="popup-close" href="#" class="close" onclick="hideLayer('chooseColorPopup'); return false;"><span>Close</span></a>
			</div>
			<div class="popupContent">
				<form id="chooseColor" name="chooseColor" method="post" action="">				
					<div style="width:100%;text-align:center">
					<a href="javascript:void(0)" onclick="resetColor();">Reset</a>
					</div>
					<div class="itemChange">
						<div class="colorItem">
							<p>							
								<span>Background picture:</span>	
								<a href="javascript:void(0)" onclick="openBgr();">Open BG</a>
								<input type="hidden" name="bgBodyInput" id="bgBodyInput" value="<?php echo $this->params['bgbody'];?>"/>
							</p>
							<p>
								<span>Background Block:</span>
							  	<input size="13" name="bgblockColorInput" id="bgblockColorInput" type="hidden" value="<?php echo $this->params['bgblock'];?>" />
							  	<label style="background-color: <?php echo $this->params['bgblock'];?>;" class="color-box" id="bgblockColor"></label>
							</p>
							<p>
								<span>Wall color:</span>
							  	<input size="13" name="bgWallColorInput" id="bgWallColorInput" type="hidden" value="<?php echo $this->params['bgwall'];?>" />
							  	<label style="background-color: <?php echo $this->params['bgwall'];?>;" class="color-box" id="bgWallColor"></label>
							</p>
							<p>
								<span>Text on Wall:</span>
							  	<input size="13" name="textWallColorInput" id="textWallColorInput" type="hidden" value="<?php echo $this->params['textwall'];?>" />
							  	<label style="background-color: <?php echo $this->params['textwall'];?>;" class="color-box" id="textWallColor"></label>
							  
							</p>
							<p>
								<span>Text on Wall Link:</span>
							  	<input size="13" name="textWallLinkColorInput" id="textWallLinkColorInput" type="hidden" value="<?php echo $this->params['textwalllink'];?>" />
							  	<label style="background-color: <?php echo $this->params['textwalllink'];?>;" class="color-box" id="textWallLinkColor"></label>
							  
							</p>
							<p>
								<span>Line Color:</span>
							  	<input size="13" name="lineColorInput" id="lineColorInput" type="hidden" value="<?php echo $this->params['linecolor'];?>" />
							  	<label style="background-color: <?php echo $this->params['linecolor'];?>;" class="color-box" id="linecolor"></label>
							</p>
							<p>
								<span>Tab color:</span>
							  	<input size="13" name="tabColorInput" id="tabColorInput" type="hidden" value="<?php echo $this->params['tabcolor']?>" />
							  	<label style="background-color: <?php echo $this->params['tabcolor']?>;" class="color-box" id="tabcolor"></label>
							</p>
							<p>
								<span>Menu Text Color:</span>
							  	<input size="13" name="menuTextColorInput" id="menuTextColorInput" type="hidden" value="<?php echo $this->params['menucolor'];?>" />
							  	<label style="background-color: <?php echo $this->params['menucolor']?>;" class="color-box" id="menuTextColor"></label>
							</p>
							<p>
								<span>Follow US Color:</span>
							  	<select name="followcolorInput" id="followcolorInput">
								  <?php 
								  $arr_rotate = array('blue','green','grey','orange','purple','red','yellow');
								  foreach($arr_rotate as $value){
								  	echo '<option value="'.$value.'" '.(($this->params['followcolor'] == $value) ? 'selected="selected"' : '').'>'.$value.'</option>';	
								  }
								  ?>							  
								</select>
							</p>
							<p>
								<span>Address:</span>
							 	<input size="13" name="addressColorInput" id="addressColorInput" type="hidden" value="<?php echo $this->params['address']?>" />
							  	<label style="background-color: <?php echo $this->params['address']?>;" class="color-box" id="addressColor"></label>
							</p>
							<p>
							<span>Phone Number/Email:</span>
							  <input size="13" name="phoneColorInput" id="phoneColorInput" type="hidden" value="<?php echo $this->params['phone']?>" />
							  <label style="background-color: <?php echo $this->params['phone']?>;" class="color-box" id="phoneColor"></label>							  
							</p>
							<p>
								<span>Hour Of Operation:</span>
							  	<input size="13" name="hourColorInput" id="hourColorInput" type="hidden" value="<?php echo $this->params['hour']?>" />
							  	<label style="background-color: <?php echo $this->params['hour']?>;" class="color-box" id="hourColor"></label>							  
							</p>		
							<p>
								<span>Hour Of Operation Text:</span>
							  	<input size="13" name="hourTextColorInput" id="hourTextColorInput" type="hidden" value="<?php echo $this->params['hourtext']?>" />
							  	<label style="background-color: <?php echo $this->params['hourtext']?>;" class="color-box" id="hourTextColor"></label>
							</p>
							<p>&nbsp;</p>
						</div>
					</div>
					<input type="hidden" name="resetColor" value="0" id="resetColor" />
					<input type="hidden" name="saveColor" value="1" />					
				</form>
			</div>
		</div>
	<?php }?>
<jdoc:include type="modules" name="debug" />
</body>
</html>
